#ifndef __STDTYPE_H
#define __STDTYPE_H
#include "platform.h"
#include "mxsetup.h"
#include "arch.h"

/* null object */
#define mx_null    (void*)0

/* boolean value */
#define mx_true    1
#define mx_false   0

/* common definition */
#define MX_BYTEWIDE 8
#define MX_BYTEWIDE_NUM 3
#define MX_BYTEWIDE_MASK (MX_BYTEWIDE - 1)

/* cpu bit wide relevant */
#if (MX_CPU_BITWIDE == 32)
    #define MX_CPU_BITWIDE_NUM 2
#elif (MX_CPU_BITWIDE == 64)
    #define MX_CPU_BITWIDE_NUM 3
#else
    #error MX_CPU_BITWIDE defines an error value.
#endif
#define MX_CPU_BITWIDE_BYTE (MX_CPU_BITWIDE / 8)
#define MX_CPU_BITWIDE_MASK (MX_CPU_BITWIDE_BYTE - 1)

/* cpu endian */
#ifndef MX_CPU_BIGENDIAN
    #error MX_CPU_BIGENDIAN undefined.
#endif

/* value limit of standard types */
#define MX_INT8_MAX 0x7F
#define MX_INT8_MIN 0x80
#define MX_UINT8_MAX 0xFFU
#define MX_UINT8_MIN 0U
#define MX_INT16_MAX 0x7FFF
#define MX_INT16_MIN 0x8000
#define MX_UINT16_MAX 0xFFFFU
#define MX_UINT16_MIN 0U
#define MX_INT32_MAX 0x7FFFFFFF
#define MX_INT32_MIN 0x80000000
#define MX_UINT32_MAX 0xFFFFFFFFU
#define MX_UINT32_MIN 0U
#define MX_INT64_MAX 0x7FFFFFFFFFFFFFFF
#define MX_INT64_MIN 0x8000000000000000
#define MX_UINT64_MAX 0xFFFFFFFFFFFFFFFFU
#define MX_UINT64_MIN 0U

#if (MX_CPU_BITWIDE == 32)
    #define MX_SIZE_MAX MX_INT32_MAX
    #define MX_SIZE_MIN MX_INT32_MIN
    #define MX_USIZE_MAX MX_UINT32_MAX
    #define MX_USIZE_MIN MX_UINT32_MIN
#elif (MX_CPU_BITWIDE == 64)
    #define MX_SIZE_MAX MX_INT64_MAX
    #define MX_SIZE_MIN MX_INT64_MIN
    #define MX_USIZE_MAX MX_UINT64_MAX
    #define MX_USIZE_MIN MX_UINT64_MIN
#else
    #error MX_CPU_BITWIDE defines an error value.
#endif

/* compiler relevant */
#include "compiler.h"

/* define unsigned 8bits pointer */
typedef mx_uint8_t* mx_uint8_pt;

/* define unsigned 16bits pointer */
typedef mx_uint16_t* mx_uint16_pt;

/* define unsigned 32bits pointer */
typedef mx_uint32_t* mx_uint32_pt;

/* define unsigned 64bits pointer */
typedef mx_uint64_t* mx_uint64_pt;

/* define signed 8bits pointer */
typedef mx_int8_t* mx_int8_pt;

/* define signed 16bits pointer */
typedef mx_int16_t* mx_int16_pt;

/* define signed 32bits pointer */
typedef mx_int32_t* mx_int32_pt;

/* define signed 64bits pointer */
typedef mx_int64_t* mx_int64_pt;

/* define unsigned machine wide pointer */
typedef mx_usize_t* mx_usize_pt;

/* define signed machine wide pointer */
typedef mx_size_t* mx_size_pt;

/* define unknown pointer */
typedef void* mx_void_pt;

/* define machine address wide */
typedef mx_usize_t mx_addr_t;

/* define machine address wide pointer */
typedef mx_usize_t* mx_addr_pt;

/* define bool type */
typedef mx_uint8_t mx_bool_t;

/* define string type */
typedef char* mx_string_pt;

/* define const string type, only variable can be modify */
typedef const char* mx_cstring_pt;

#endif
